<template>
	<view class="">	
	<view style=" display: flex;justify-content: center;
		background-color: #CFEAF1;height: 44px;width: 100%;
		align-items: center;position: sticky;top: 0;z-index: 1;
		">
			<h3>首页</h3>
		</view>
	<view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiper">
				<view class="swiper-item" style="display: flex;flex-direction: column;align-items: center;">
					<image :src="item.pathImage" mode=""></image>
				</view>
			</swiper-item>
		</swiper>

		<view class="view">
			<view class="v-search" @click="tosearch">
				<uni-easyinput v-model="ttwm" placeholder="点击搜索外卖" suffixIcon="search"/>
			</view>
		</view>

		<view class="view">
			<view style="width: 90%;margin-top: 10px;margin-bottom: 70px;">
				<uni-list style="margin-top: 10px;" v-for="(item,index) in foodlist">
					<uni-list-item :title="item.foodname" :note="'￥'+item.price" :thumb="item.image" thumb-size="lg"
						rightText="查看详情" clickable @click="detail(item.foodId)">
					</uni-list-item>
				</uni-list>
			</view>
		</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiper: [{

				}],
				ttwm: '',
				foodlist: [{

				}],
				ip:''
			}
		},
		methods: {
			tosearch(){
				uni.navigateTo({
					url:'/pages/search/search'
				})
			},
			detail(id) {
				uni.navigateTo({
					url: '../fooddetails/fooddetails'
				});
				// try {
				// 	uni.setStorageSync('foodid', id);
					
				// } catch (e) {
					
				// }
				
				uni.setStorage({
					key:"foodid",
					data:id
				})
			}
		},
		onShow() {
			// uni.request({
			// 					url: 'http://pv.sohu.com/cityjson?ie=utf-8',
			// 					method: 'POST',
			// 					success: res => {
			// 						const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
			// 						let ip = reg.exec(res.data);
			// 						_this.ip = ip[0];
			// 						console.log(ip[0]);
			// 					}
			// 				});
			// uni.request({
			// 	url: 'http://localhost:8484/ttwm/ttwm/IP',
			// 	method: 'POST',
			// 	data: {},
			// 	success: res => {
			// 		this.ip=res.data.IP
			// 		console.log(this.ip);
			// 	},
			// 	fail: () => {},
			// 	complete: () => {}
			// });
			uni.request({
				url: 'http://localhost:8484/ttwm/ttwm/foodAll',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.foodlist = res.data.list
						// console.log(this.foodlist[9].image);
					}
				},
				fail: () => {},
				complete: () => {}
			});
			uni.request({
				url: 'http://localhost:8484/ttwm/ttwm/swiperAll',
				method: 'POST',
				data: {},
				success: res => {
					if (res.data.success) {
						this.swiper = res.data.list
						// uni.showToast({
						// 	title: '成功',
						// 	icon: 'none'
						// });
					}
				},
				fail: () => {},
				complete: () => {}
			});
			
		
		}
	}
</script>

<style>
	.view {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.v-search {
		width: 80%;
		height: 32px;
		margin-top: 20px;

	}

	.swiper-item {
		margin-top: 10px;
	}
</style>